/**
 * 
 */
package com.nari.interfaces.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;

import com.nari.coreframe.dao.hibernate3.GenericDaoImpl;
import com.nari.interfaces.model.IHeatMeterData24Gather;
import com.nari.platform.date.CalendarUtils;
import com.nari.platform.model.ResponseMsg;

/**
 * 
 * @author Xiaopeng
 * @date 2015-1-12
 */
public class HeatMeterData24GatherDaoImpl extends GenericDaoImpl<IHeatMeterData24Gather, String>
		implements IHeatMeterData24GatherDao {
	
	/**
	 * 按统计批次查询热量表分时数据列表
	 * @param meterNo
	 * @param recordTime
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-22
	 */
	@SuppressWarnings("unchecked")
	public List<IHeatMeterData24Gather> queryMeterDataList4Statis(String meterNo, 
			Date recordTime) throws Exception {
		//抄表时间修正
		Date recordTimeStart = CalendarUtils.getMinCalBasedSrcCal(CalendarUtils.getInstance(recordTime));
		Date recordTimeEnd = CalendarUtils.getMaxCalBasedSrcCal(CalendarUtils.getInstance(recordTime));
		String hsql = "from IHeatMeterData24Gather hmd24 " +
				"where hmd24.meterNo='"+meterNo+"' " +
				"and hmd24.recordTime between :startDate and :endDate " +
				"order by hmd24.recordTime desc";
		Query query = this.getCurrentSession().createQuery(hsql);
		return query.setTimestamp("startDate", recordTimeStart)
				.setTimestamp("endDate", recordTimeEnd)
				.list();
	}
	
	/**
	 * 按统计批次删除热量表分时数据
	 * @param meterNo
	 * @param recordTime
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-22
	 */
	public ResponseMsg deleteMeterDataStatis(String meterNo, Date recordTime) throws Exception {
		//抄表时间修正
		Date recordTimeStart = CalendarUtils.getMinCalBasedSrcCal(CalendarUtils.getInstance(recordTime));
		Date recordTimeEnd = CalendarUtils.getMaxCalBasedSrcCal(CalendarUtils.getInstance(recordTime));
		String hsql = "delete from IHeatMeterData24Gather hmd24 " +
				"where hmd24.meterNo='"+meterNo+"' " +
				"and hmd24.recordTime between :startDate and :endDate " +
				"order by hmd24.recordTime desc";
		Query query = this.getCurrentSession().createQuery(hsql);
		int exeResult = query.setTimestamp("startDate", recordTimeStart)
				.setTimestamp("endDate", recordTimeEnd)
				.executeUpdate();
		System.out.println(exeResult);
		return ResponseMsg.getInstance(true);
	}
}
